package riceSystem.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import riceSystem.dao.LoginTemplateInterface;
import riceSystem.entity.Administrator;
@Component("administratorLogin")
public class AdministratorLoginImpl implements LoginTemplateInterface<Administrator> {
	
	private HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
	@SuppressWarnings("unchecked")
	public Administrator login(String userName,String passWord){
		List<Administrator> admin = hibernateTemplate.find("from Administrator admin where admin.username= ? and admin.password = ?",new String[]{userName,passWord});
		if(admin.size()==1){
			return admin.get(0);
		}
		return null;
	}
}
